<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Reception extends Controller_Tpl {
    //private $_data;

	public function before()
	{
		parent::before();
	}

	public function after()
	{
		parent::after();
	}
	
	public function action_index()
	{
		$query = DB::select()
			->from('leads')
			->join('clients','LEFT')
			->on('leads.leadsid', '=', 'clients.lead_id')
			->where('clients.status_id','=',1);
		$pagination_query = clone $query;
		$count = $pagination_query->select(DB::expr('COUNT(*) AS count'))->execute()->get('count');

		$config = Kohana::$config->load('pagination');
		$pagination = Pagination::factory(array(
			'total_items' => $count,
			'current_page'   => array('source' => 'route', 'key' => 'page'),
			'items_per_page' => 20,
			'view'           => 'pagination/floating',
			'auto_hide'      => TRUE,
		));
		$this->_data['page_links'] = $pagination->render();

		$query->order_by('date', 'DESC')
			->limit($pagination->items_per_page)
			->offset($pagination->offset);
		$this->_data['leads'] = $query->execute()->as_array();
		$this->_data['table_new'] = View::factory($this->_data['controller'].'/blocks/leadstable',$this->_data);

	}

} // End Reception